import request from '@/utils/request'

// 用户登录
export function login(data) {
  return request({
    url: '/api/user/login',
    method: 'post',
    data,
    // 登录接口不需要Authorization头
    skipAuth: true
  })
}

//发送邮箱验证码
export function getEmailCode(email) {
  return request({
    url: `/system/email/getCode/${email}`,
    method: 'get',
    // 获取验证码接口不需要Authorization头
    skipAuth: true
  })  
}

// 邮箱登录
export function loginByEmail(email, verifyCode) {
  return request({
    url: '/system/login/login_by_email',
    method: 'post',
    data: {
      email,
      verifyCode
    },
    // 登录接口不需要Authorization头
    skipAuth: true
  })
}

// 邮箱账号密码登录
export function loginByEmailPwd(email, password) {
  return request({
    url: '/system/login/login_by_pwd',
    method: 'post',
    data: {
      email,
      password
    },
    // 登录接口不需要Authorization头
    skipAuth: true
  })
}

// 用户注册
export function register(data) {
  return request({
    url: '/api/user/register',
    method: 'post',
    data,
    // 注册接口不需要Authorization头
    skipAuth: true
  })
}

// 获取用户信息
export function getUserInfo() {
  return request({
    url: '/api/user/info',
    method: 'get'
  })
}

// 根据UID获取用户信息
export function getUserInfoById(uid) {
  return request({
    url: '/system/user/get',
    method: 'get',
    params: {
      id: uid
    }
  })
}

// 上传文件
export function uploadFile(file) {
  const formData = new FormData()
  formData.append('file', file)
  
  return request({
    url: '/system/file/upload',
    method: 'post',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}

// 更新用户信息
export function updateUserInfo(data) {
  return request({
    url: '/system/user/update',
    method: 'put',
    data
  })
}

// 修改密码
export function changePassword(id, password) {
  return request({
    url: `/system/login/update_password/${id}/${password}`,
    method: 'post'
  })
}

// 获取用户个人中心统计数据
export function getUserCenterCount() {
  return request({
    url: '/forum/post/count',
    method: 'get'
  })
}

// 获取当前用户权限
export function getCurrentUserPermissions(uid) {
  return request({
    url: '/system/permission/current_user_permissions',
    method: 'get',
    params: {
      uid
    }
  })
}